package com.ttwl.www.app;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ttwl.www.app.meFrame.myDown.MyDownActivity;
import com.ttwl.www.app.meFrame.myCollectFrame.MyCollectActivity;
import com.ttwl.www.app.meFrame.personInfoFrame.personInfoActivity;
import com.ttwl.www.app.meFrame.myCourseFrame.MyCourseActivity;

public class MeFragment extends Fragment {
    private TextView myStudio,tvMyCourse,tvMyCollect,tvMyDown;
    private ImageView goPersonInfo;
    public MeFragment() {

    }

    public static MeFragment newInstance() {
        MeFragment fragment = new MeFragment();
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_me, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        //控制icon图标大小
        myStudio = (TextView) view.findViewById(R.id.my_studio);
        tvMyCourse = (TextView) view.findViewById(R.id.tv_mycourse);
        tvMyCollect = (TextView) view.findViewById(R.id.tv_mycollect);
        tvMyDown = (TextView) view.findViewById(R.id.tv_mydown);

        Drawable iconStudioMy = getResources().getDrawable(R.drawable.icon_studio_my);
        iconStudioMy.setBounds(0, 0, 40, 40);//第一0是距左边距离，第二0是距上边距离，40分别是长宽
        myStudio.setCompoundDrawables(iconStudioMy, null, null, null);//只放左边
        //跳转到个人中心
        goPersonInfo = (ImageView) view.findViewById(R.id.go_personinfo);
        setListeners();
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onDetach() {
        super.onDetach();

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        //取消异步
    }
    private void setListeners() {
        OnClick onClick = new OnClick();
        goPersonInfo.setOnClickListener(onClick);
        tvMyCourse.setOnClickListener(onClick);
        tvMyCollect.setOnClickListener(onClick);
        tvMyDown.setOnClickListener(onClick);
    }
    private class OnClick implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            Intent intent = null;
            switch (v.getId()) {
                case R.id.go_personinfo:
                    //跳转到个人信息界面
                    intent = new Intent(getActivity(),personInfoActivity.class);
                    break;
                case R.id.tv_mycourse:
                    //跳转到我的课程
                    intent = new Intent(getActivity(),MyCourseActivity.class);
                    break;
                case R.id.tv_mycollect:
                    //跳转到我的收藏
                    intent = new Intent(getActivity(),MyCollectActivity.class);
                    break;
                case R.id.tv_mydown:
                    //跳转到我的下载
                    intent = new Intent(getActivity(),MyDownActivity.class);
                    break;
            }
            startActivity(intent);
        }
    }
}
